package com.jml.mapreduce.分组比较器;

import com.jml.mapreduce.wordcount.WordcountDriver;
import com.jml.mapreduce.wordcount.WordcountMapper;
import com.jml.mapreduce.wordcount.WordcountReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class OrderDrive {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // 1 获取配置信息以及封装任务
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);
        // 2 设置jar加载路径
        job.setJarByClass(OrderDrive.class);
        // 3 设置map和reduce类
        job.setMapperClass(OrderMapper.class);
        job.setReducerClass(OrderReduce.class);
        // 4 设置map输出
        job.setMapOutputKeyClass(OrderBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        /**
         *
         */
        job.setGroupingComparatorClass(OrderComparator.class);

        // 5 设置最终输出kv类型
        job.setOutputKeyClass(OrderBean.class);
        job.setOutputValueClass(NullWritable.class);
        // 6 设置输入和输出路径
        FileInputFormat.setInputPaths(job, new Path("D:\\tmp\\bigDate\\input"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\tmp\\bigDate\\output2"));
        // 7 提交
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
